package Qieces;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.io.File;
import java.io.IOException;

/**
 * 棋子类
 *
 */
public abstract class Qiece {

    //棋子种类：1.将（帅） 2.士 3.相 4.车 5.马 6.炮 7.卒（兵）0.死亡
    protected int kind;

    //选中状态
    protected int scl;

    public int getMoveof() {
        return moveof;
    }

    public void setMoveof(int moveof) {
        this.moveof = moveof;
    }

    //是否可移动至该格
    protected int moveof;

    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }

    //棋子绘画坐标
    protected int x;
    protected int y;

    public int getKind() {
        return kind;
    }

    public void setKind(int kind) {
        this.kind = kind;
    }

    public int getController() {
        return controller;
    }

    public void setController(int controller) {
        this.controller = controller;
    }

    //棋子所属阵营：0.黑 1.红
    protected int controller;

    //导入棋子贴图
    protected static Image generals_b;        //将（帅）
    protected static Image generals_r;
    protected static Image assistants_b;      //士
    protected static Image assistants_r;
    protected static Image ministers_b;       //相
    protected static Image ministers_r;
    protected static Image chariots_b;        //车
    protected static Image chariots_r;
    protected static Image horses_b;          //马
    protected static Image horses_r;
    protected static Image cannons_b;         //炮
    protected static Image cannons_r;
    protected static Image soldier_b;         //卒（兵）
    protected static Image soldier_r;

    protected static Image point;

    //加载棋子贴图
    static {
        try {
            generals_b = ImageIO.read(new File("src/img/b_j.png"));
            assistants_b = ImageIO.read(new File("src/img/b_s.png"));
            ministers_b = ImageIO.read(new File("src/img/b_x.png"));
            chariots_b = ImageIO.read(new File("src/img/b_c.png"));
            horses_b = ImageIO.read(new File("src/img/b_m.png"));
            cannons_b = ImageIO.read(new File("src/img/b_p.png"));
            soldier_b = ImageIO.read(new File("src/img/b_z.png"));
            generals_r = ImageIO.read(new File("src/img/r_j.png"));
            assistants_r = ImageIO.read(new File("src/img/r_s.png"));
            ministers_r = ImageIO.read(new File("src/img/r_x.png"));
            chariots_r = ImageIO.read(new File("src/img/r_c.png"));
            horses_r = ImageIO.read(new File("src/img/r_m.png"));
            cannons_r = ImageIO.read(new File("src/img/r_p.png"));
            soldier_r = ImageIO.read(new File("src/img/r_z.png"));
            point = ImageIO.read(new File("src/img/dot.png"));
        } catch (IOException e) {
            e.printStackTrace();
            System.out.println("棋子图片加载失败！");
        }
    }


    //贴图绘制
    public abstract void paintSelf(Graphics g);

    public int getScl() {
        return scl;
    }

    public void setScl(int scl) {
        this.scl = scl;
    }

    //棋子是否被选中
    public boolean select(int x, int y){
        if (this.kind != 0){
            if (this.x <= x && this.x + 69 >= x) {
                if (this.y <= y && this.y + 69 >= y) {
                    this.scl = 1;
                    return true;
                }
            }
        }
        return false;
    }

    //棋子的移动范围（包括攻击及移动）
    public abstract void movingRange(Qiece[] qieces, int row, int col);




}
